import Config
import os
import sys
from component.Opt import Opt
from component.Upload import Upload
from component.Mysql import Mysql


class AutoFactory:

    def __init__(self):
        self.sys = sys
        self.os = os
        try:
            # 连接设备构建opt对象
            self.opt = Opt(Config.DEVICE_HOST + ":" + str(Config.DEVICE_PORT))
            self.device = self.opt.d
            self.upload = Upload(self.opt)
            # 连接数据库
            if Config.MYSQL_ACTIVATE:
                print("初始化mysql....")
                self.mysql = Mysql(Config.MYSQL_HOST, Config.MYSQL_PORT, Config.MYSQL_USER, Config.MYSQL_PASSWORD,
                                   Config.MYSQL_DATABASE)
            print("AutoFactory自动化工厂初始化完成....")
        except Exception as e:
            print(f"AutoFactory自动化工厂初始化失败，原因：{e}")
            sys.exit(1)
